// packageI/ecosphere_watercooler/water_use/components/card/card.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    member: {
      type: Object,
    },
    mini_url: {
      type: String
    },
    list: {
      type: Array
    },
    device_no:{
      type:String
    },
    share:{
      type:String|Number
    },
    course_name:{
      type:String
    }
  },
  observers:{
    "share":function(number){
      if(number){
        this.setData({
          card:'**************',
          mobile:'***********',
          balance:"****"
        })
      }
    },
    "member":function(obj){
      let {card,member} = obj;
      this.setData({card:card.card_no,balance:card.balance,mobile:member.mobile})
    }
  },
  options: {
    addGlobalClass: true,
  },
  data: {
    active: 0,
    card:'',
    mobile:'',
    balance:"",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    no_card_link(){
      wx.navigateTo({
        url: '/packageI/ecosphere_watercooler/water_use/no_card/no_card?device_no='+this.data.device_no,
      })
    },
    ewn() {
      wx.scanCode({
        success: (res) => {
          
          if(res.path){
            wx.navigateTo({
              url: '/'+res.path,
            })
          }else{
            wx.showToast({
              title: '跳转失败',
              icon: 'none',
              duration: 2000
            })
          }
  
        },
        fail: (res) => {
          console.log(res);
          wx.showToast({
            title: '跳转失败',
            icon: 'none',
            duration: 2000
          })
        }
      })
    },
    onChange(event) {
      let active = event.detail.index
      this.setData({
        active
      })
      this.triggerEvent("onChange", event.detail.index)
    },
    delete_card(){
      this.triggerEvent("delete_card")
    },
    course(){
      wx.navigateTo({
        url: this.properties.mini_url,
      })
    },
    goto(e) {
      let url  = e.currentTarget.dataset.url;
      if(url == 'fetch_water'){
        wx.navigateTo({
          url: `/packageI/ecosphere_watercooler/water_use/${url}/${url}?device_no=${this.data.device_no}`
        })
      }else if(url=='bind'){
        wx.navigateTo({
          url: `/packageI/ecosphere_watercooler/water_use/${url}/${url}?device_no=${this.data.device_no}`
        })
      }else{
        wx.navigateTo({
          url: `/packageI/ecosphere_watercooler/water_use/${url}/${url}`
        })

      }
    },
  }
})